<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>树形菜单选项卡结合 </title>
		<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../js/easyui/locale/easyui-lang-zh_CN.js"></script>
		<link rel="stylesheet" href="../js/easyui/themes/default/easyui.css" />
		<link rel="stylesheet" href="../js/easyui/themes/icon.css" />
		<script type="text/javascript" src="../js/ztree/jquery.ztree.all-3.5.js"></script>
		<link rel="stylesheet" href="../js/ztree/zTreeStyle.css" />
		<script type="text/javascript">
			$(function() {
				//启动简单树形菜单
				var setting = {
					data: {
						simpleData: {
							enable: true
						}
					},
					callback: {
						onClick: zTreeOnClick
					}
				};
				//给树形菜单赋值
				var zNodes = [{
					id: 1,
					pId: 0,
					name: "父节点1"
				}, {
					id: 2,
					pId: 0,
					name: "父节点2"
				}, {
					id: 11,
					pId: 1,
					name: "子节点1"
				}, {
					id: 12,
					pId: 1,
					name: "子节点2"
				}, {
					id: 13,
					pId: 2,
					name: "传智播客",
					page: "http://www.itcast.cn"
				}, {
					id: 14,
					pId: 2,
					name: "百度",
					page: "http://www.baidu.com"
				}];
				//zTree 第三步初始化
				$.fn.zTree.init($("#baseMenu"), setting, zNodes);
				$('#myTabs').tabs({
					onContextMenu: function(e, title, index) {
						e.preventDefault();
						$('#mm').menu('show', {
							left: e.pageX,
							top: e.pageY
						});
					}
				});
				$("#closeCurrent").click(function() {
					//获取选中的标签索引
					var tab = $('#myTabs').tabs('getSelected');
					var index = $('#myTabs').tabs('getTabIndex', tab);
					$("#myTabs").tabs("close", index);
				});
				//关闭选中标签之外的标签
				$("#closeOthers").click(function() {
					//获取所有标签
					var tabs = $("#myTabs").tabs("tabs");
					var length = tabs.length;
					//获取选中标签的索引
					var tab = $('#myTabs').tabs('getSelected');
					var index = $('#myTabs').tabs('getTabIndex', tab);
					//关闭选中标签之前的标签
					for (var i = 0; i < index; i++) {
						$("#myTabs").tabs("close", 0);
					}
					//关闭选中标签之后的标签
					for (var i = 0; i < length - index - 1; i++) {
						$("#myTabs").tabs("close", 1);
					}
				});
				//关闭所有标签
				$("#closeAll").click(function() {
					var tabs = $("#myTabs").tabs("tabs");
					var length = tabs.length;
					for (var i = 0; i < length; i++) {
						$("#myTabs").tabs("close", 0);
					}
				});
			});

			function zTreeOnClick(event, treeId, treeNode) {
				var content = '<div style="width:100%;height:100%;overflow:hidden;">' + '<iframe src="' + treeNode.page + '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';
				if (treeNode.page != null && treeNode.page != undefined) {
					if ($("#myTabs").tabs('exists', treeNode.name)) {
						$("#myTabs").tabs('select', treeNode.name);
					} else {
						$("#myTabs").tabs('add', {
							title: treeNode.name,
							content: content,
							closable: true
						});
					};
				};
			};
		</script>
	</head>

	<body class="easyui-layout">
		<div data-options="region:'north',title:'North Title',split:true" style="height:100px;"></div>
		<div data-options="region:'south',title:'South Title',split:true" style="height:100px;"></div>
		<div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width:100px;"></div>
		<div data-options="region:'west',title:'West',split:true" style="width:200px;">
			<div class="easyui-accordion" data-options="fit:'true'">
				<div data-options="iconCls:'icon-save',title:'基础设置'"></div>
				<div data-options="iconCls:'icon-save',title:'系统设置'">
					<ul id="baseMenu" class="ztree"></ul>
				</div>
				<div data-options="iconCls:'icon-save',title:'人员管理'"></div>
			</div>
		</div>
		//选项卡显示
		<div data-options="region:'center',title:'center title'" style="padding:5px;background:#eee;">
			<div id="myTabs" data-options="fit:true" class="easyui-tabs">
				<div data-options="fit:true,title:'选项卡一',iconCls:'icon-reload',closable:true">选项卡一</div>
				<div data-options="fit:true,title:'选项卡二',iconCls:'icon-reload',closable:true">选项卡二</div>
				<div data-options="fit:true,title:'选项卡三',iconCls:'icon-reload',closable:true">选项卡三</div>
			</div>
		</div>

		<!--菜单 -->
		<!--<div id="mm" class="easyui-menu">
			<div >关闭当前窗口</div>
			<div >关闭其他窗口</div>
			<div class="menu-sep"></div> 
			<div data-options="iconCls:'icon-cancel'">关闭所有窗口</div>
		</div>-->
		<div id="mm" class="easyui-menu" style="width:120px;">
			<div id="closeCurrent" name="closeCurrent" data-options="iconCls:'icon-no'">关闭当前</div>
			<div id="closeOthers" name="closeOthers" data-options="iconCls:'icon-no'">关闭其它</div>
			<div class="menu-sep"></div>
			<div id="closeAll" name="closeAll" data-options="iconCls:'icon-cancel'">关闭所有</div>
		</div>

	</body>

</html>